package cms.manage.template.value.impl;

import cms.bean.PageView;
import cms.bean.question.Answer;
import cms.bean.question.Question;
import cms.bean.question.QuestionTag;
import cms.bean.template.Forum;
import cms.manage.template.impl.QuestionTagTemplateManage;
import cms.manage.template.impl.QuestionTemplateManage;
import cms.manage.template.value.TplValueStrategy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import static cms.common.SystemConstant.DisplayType.*;

@Service("问答")
public class QuestionStrategy implements TplValueStrategy {
    @Resource
    QuestionTemplateManage questionTemplateManage;// 问题 -- 模板方法实现
    @Resource
    QuestionTagTemplateManage questionTagTemplateManage;// 问题标签 -- 模板方法实现
    @Override
    public Object doOperation(Forum forum, Map submitParameter, Map runtimeParameter) {
        if(forum.getForumChildType().equals("问题列表")){
            if(forum.getDisplayType().equals(DISPLAY_PAGE.getValue())){//分页
                PageView<Question> value = questionTemplateManage.questionPage(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("问题内容")){
            if(forum.getDisplayType().equals(DISPLAY_ENTITYBEAN.getValue())){//实体对象
                Question value = questionTemplateManage.contentEntityBean(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("答案列表")){
            if(forum.getDisplayType().equals(DISPLAY_PAGE.getValue())){//分页
                PageView<Answer> value = questionTemplateManage.answerPage(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("添加问题")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = questionTemplateManage.addQuestionCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("追加问题")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = questionTemplateManage.appendQuestionCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("添加答案")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = questionTemplateManage.addAnswerCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("修改答案")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = questionTemplateManage.editAnswerCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("回复答案")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = questionTemplateManage.replyAnswerCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("修改答案回复")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = questionTemplateManage.editAnswerReplyCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("采纳答案")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = questionTemplateManage.adoptionAnswerCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("回答总数")){
            if(forum.getDisplayType().equals(DISPLAY_ENTITYBEAN.getValue())){//实体对象
                Long value = questionTemplateManage.answerCountEntityBean(forum, submitParameter, runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("相似问题")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                List<Question> value = questionTemplateManage.questionLikeCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else  if(forum.getForumChildType().equals("问题标签列表")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                List<QuestionTag> value = questionTagTemplateManage.questionTagCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }
        return null;
    }
}
